package com.yanqu.road.server.cmd.activity.flowerstudy;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross.activity.CrossActivityProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_FLOWER_STUDY_CROSS_ACTIVITY_GET_RANK_REWARD, desc = "花城书房领取跨服活动奖励")
public class CrossFlowerStudyGetRankRewardCmd extends CrossCommand {

    private int activityId;
    private int conditionId;
    private long userId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossActivityProto.CrossActivityGetRewardReqMsg reqMsg = CrossActivityProto.CrossActivityGetRewardReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        conditionId = reqMsg.getConditionId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        int myRank = -1;
        ActivityConditionInfo activityConditionInfo = ActivityMgr.getActivityConditionInfo(activityId, conditionId);
        if(null != activityConditionInfo){
            myRank = ActivityRankMgr.getNewCrossActivityRank(activityId, activityConditionInfo.getType(), serverId, userId);
        }
        CrossActivityProto.CrossActivityGetRewardRespMsg.Builder respMsg = CrossActivityProto.CrossActivityGetRewardRespMsg.newBuilder();
        respMsg.setActivityId(activityId);
        respMsg.setConditionId(conditionId);
        respMsg.setRank(myRank);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_FLOWER_STUDY_CROSS_GET_RANK_REWARD, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
